package com.example.l2p_feedback;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.widget.Toast;

public class View06_Splash extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.view06_splash);
		
		// Get intent, action and MIME type
		Intent intent = getIntent();
		String action = intent.getAction();
		String type = intent.getType();

		if (Intent.ACTION_SEND.equals(action) && type != null) {
			if ("text/plain".equals(type)) {
				String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
				if (sharedText != null) {
					// Update UI to reflect text being shared
					SharedPreferences settings = PreferenceManager
							.getDefaultSharedPreferences(this);
					SharedPreferences.Editor editor = settings.edit();
					editor.putString("token", sharedText).commit();
					
					Toast.makeText(this, "AccessToken: "+sharedText, Toast.LENGTH_LONG).show();
					new Handler().postDelayed(new Runnable() {
			            @Override
			            public void run() {
			                Intent i = new Intent(View06_Splash.this, View04_Homepage.class);
			                startActivity(i);
			                finish();
			            }
			        }, 5000);
				}
			}
		}
	}
}